package com.google.shop.product.sms.controller;

import com.google.shop.product.common.utils.R;
import com.google.shop.product.sms.service.SmsService;
import com.google.shop.product.sms.utils.RandomUtil;
import com.google.shop.product.sms.utils.UserAgentUtils;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/sms"})
@RestController
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/sms/controller/SmsController.class */
public class SmsController {
    @Autowired
    private SmsService smsService;

    @GetMapping({"/send/{phone}"})
    public R sendSms(@PathVariable String phone) {
        Object code = RandomUtil.getFourBitRandom();
        Map<String, Object> param = new HashMap<>();
        param.put("code", code);
        if (this.smsService.send(param, phone)) {
            return R.ok();
        }
        return R.error("短信发送失败");
    }

    @GetMapping({"/o"})
    public R o(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Content-type", "text/html;charset=UTF-8");
        System.out.println(request);
        Object type = UserAgentUtils.getDeviceType(request);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("设备类型", type);
        map.put("获取用户代理对象", UserAgentUtils.getUserAgent(request));
        map.put("是否是PC", Boolean.valueOf(UserAgentUtils.isComputer(request)));
        map.put("是否是手机", Boolean.valueOf(UserAgentUtils.isMobile(request)));
        map.put("是否是平板", Boolean.valueOf(UserAgentUtils.isTablet(request)));
        map.put("是否是手机or平板", Boolean.valueOf(UserAgentUtils.isMobileOrTablet(request)));
        return R.ok(map);
    }
}
